Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
const timeCacheKey = "timeCacheKey";
const tabUrlKey = "customerTabUrl";

new Vue({
    el: '#app',
    data: {
        updateCache:true,
        times: new Date().getTime(),
        timestamp: {
            year: new Date().getFullYear(),
            month: new Date().getMonth() + 1,
            day: new Date().getDate(),
            hour: new Date().getHours()
        },
        timestamp_end: {
            year: new Date().getFullYear(),
            month: new Date().getMonth() + 1,
            day: new Date().getDate(),
            hour: new Date().getHours()
        },
        customerTabUrl:''
    },
    mounted:function(){
        this.customerTabUrl = localStorage.getItem(tabUrlKey)
    },
    computed:{
        start:function(){
            var date = "".concat(this.timestamp.year,'-',this.timestamp.month,'-',this.timestamp.day," 00:00:00");
            var hour = "".concat(this.timestamp.year,'-',this.timestamp.month,'-',this.timestamp.day," ",this.timestamp.hour,":00:00");
            var res = [
                new Date(date).getTime(), // 00:00:00
                new Date(hour).getTime(),     // hour:00:00
                hour,
            ]
            return res
        },
        end:function(){
            var hour = "".concat(this.timestamp_end.year,'-',this.timestamp_end.month,'-',this.timestamp_end.day," ",+this.timestamp_end.hour,':00:00')
            var res = [
                new Date("".concat(this.timestamp_end.year,'-',this.timestamp_end.month,'-',+this.timestamp_end.day + 1," 00:00:00")).getTime() - 1 , // 23:59:59.999
                new Date("".concat(this.timestamp_end.year,'-',this.timestamp_end.month,'-',this.timestamp_end.day," ",+this.timestamp_end.hour + 1,":00:00")).getTime() - 1, // HOUR:59:59.999
                hour,
            ]
            return res;
        },
        format:function(){
            var res = [
                new Date(+this.times).Format("yyyy-MM-dd hh:mm:ss"),new Date(+this.times).Format("yyyy-MM-dd hh:mm:ss.S"),this.times,
            ]
            return res
        }
        ,cacheItem:function(){
            var res = [],update = this.updateCache;
            var str = localStorage.getItem(timeCacheKey)
            if(undefined != str && null != str && '' != str){
                res = JSON.parse(str)
            }
            return [res,res.length]
        }
    },
    methods:{
        changeEvent(type){
            var str = localStorage.getItem(timeCacheKey)
            if(null == str || '' == str || undefined == str ){
                str = []
            }else {
                str = JSON.parse(str)
            }
            switch(type){
                case 1:
                    str.unshift("".concat(this.start[2],'@',this.start[0],'@',this.start[1]))
                    //localStorage.setItem(localStorage.length,"".concat(this.start[2],'@',this.start[0],'@',this.start[1]));
                    break;
                case 2:
                    str.unshift("".concat(this.end[2],'@',this.end[0],'@',this.end[1]));
                    // localStorage.setItem(localStorage.length,"".concat(this.end[2],'@',this.end[0],'@',this.end[1]));
                    break;
                case 3:
                    str.unshift("".concat(this.format[2],'@',this.format[0],'@',this.format[1]))
                    // localStorage.setItem(localStorage.length,"".concat(this.format[2],'@',this.format[0],'@',this.format[1]));
                    break;
            }
            str = str.slice(0,10)
            localStorage.setItem(timeCacheKey,JSON.stringify(str))
            this.updateCache = !this.updateCache
        },
        clearCache(){
            localStorage.removeItem(timeCacheKey)
            this.updateCache = !this.updateCache
        },
        changeUrl(){
            localStorage.setItem(tabUrlKey,this.customerTabUrl)
            this.updateCache = !this.updateCache
            this.$message('保存成功!');
        }
    }
})